import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';
import 'package:get/get.dart';

import 'const/const.dart';
import 'modules/home/home_controller.dart';
import 'routes/app_binding.dart';
import 'routes/app_pages.dart';

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await requestPermission();
  BluetoothManager.key = navigatorKey;
  // BluetoothManager.autoConnectDuringScan = true;
  BluetoothManager.isScanloop = true;
  BluetoothManager.instance.startScan(deviceNameFilter: [filterName], duration: const Duration(seconds: 3));
  await Future.delayed(const Duration(milliseconds: 800)); // 等待一段时间确保停止

  // AppBindings.initGetx();
  runApp(const MyApp());
}

Future<void> requestPermission() async {
  BluetoothManager.instance.requestPermissions();
  BluetoothManager.maxConnectedEnable = 1;
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of yourg application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      navigatorKey: navigatorKey,
      title: '灭火器监测',

      /// 💡 跟随系统语言
      locale: null,

      theme: ThemeData(
        splashColor: bgColor.withOpacity(0.5),
        // brightness: Brightness.dark, // 启用暗色主题
        scaffoldBackgroundColor: bgColor, // 页面背景黑色
        appBarTheme: const AppBarTheme(
          centerTitle: true,
          backgroundColor: Colors.transparent, // AppBar 背景黑色
          foregroundColor: Colors.white, // AppBar 图标、文字白色
          elevation: 0,
        ),
        iconTheme: const IconThemeData(color: Colors.white), // 图标颜色
        textTheme: const TextTheme(
          bodyMedium: TextStyle(color: Colors.white), // 正文文字白色
        ),
      ),
      initialRoute: AppPages.INITIAL,
      initialBinding: AppBinding(),
      getPages: AppPages.routes,
      debugShowCheckedModeBanner: false,
      builder: EasyLoading.init(),
    );
  }
}
